<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var isRobotBounded = function (instructions) {
      instructions = instructions.repeat(4)
      const dp = []
      let ind = 0
      for (const instruction of instructions) {
        if (instruction === 'R') {
          ind++
          ind = ind % 4
        } else if (instruction === 'L') {
          ind += 3
          ind = ind % 4
        } else {
          dp[ind] = (dp[ind] || 0) + 1
        }
      }
      return dp[0] === dp[2] && dp[1] === dp[3]
    };
    console.log(isRobotBounded("GGLLGG"))
  </script>
</body>

</html>